<template>
  <div class="menu-head">
    <div class="data menu-data">
      <div style="text-align: left;cursor: pointer;line-height: 2.5rem">
        <img src="/logo-back.png" style="width:45px">
      </div>
      <div style="text-align: right;display: flex;justify-content: right">
        <div class="menu-btn">
          <a-button type="dashed" size="large" ghost><a href="/#/home/login">登陆</a></a-button>
        </div>
      </div>
    </div>
  </div>
  <div class="one" style="  height: 100%;
  width: 100%;">
    <div style="text-align: center;color: #ffffff;margin-top: 5rem">
      <div style="font-size: 44px">四川凌空-DNS服务</div>
      <div style="font-size: 18px;margin-top: 1rem">
        简单几步完成DNS与反向代理
      </div>
      <div style="margin-top: 3rem">
        <a-button size="large" @click="downCa" ghost>下载CA证书</a-button>
      </div>
    </div>
  </div>

  <div class="bock two">
    <div>
      <div class="data" style="margin: 30px auto">
        <div style="font-size: 35px;text-align: center;margin-bottom: 50px">服务信息</div>
        <div style="background: #ececec; padding: 30px">
          <a-row :gutter="16">
            <a-col :span="8">
              <a-card>
                <a-statistic
                    title="内存使用"
                    :value="info.A"
                    suffix="GB"
                    :value-style="{ color: '#3f8600' }"
                    style="margin-right: 50px"
                >
                  <template #prefix>
                    <arrow-up-outlined/>
                  </template>
                </a-statistic>
              </a-card>
            </a-col>
            <a-col :span="8">
              <a-card>
                <a-statistic
                    title="剩余内存"
                    :value="info.B"
                    suffix="GB"
                    class="demo-class"
                    :value-style="{ color: '#cf1322' }"
                >
                  <template #prefix>
                    <arrow-down-outlined/>
                  </template>
                </a-statistic>
              </a-card>
            </a-col>
            <a-col :span="8">
              <a-card>
                <a-statistic
                    title="使用磁盘"
                    :value="info.C"
                    suffix="GB"
                    :value-style="{ color: '#3f8600' }"
                    style="margin-right: 50px"
                >
                  <template #prefix>
                    <arrow-up-outlined/>
                  </template>
                </a-statistic>
              </a-card>
            </a-col>
          </a-row>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import {ArrowUpOutlined, ArrowDownOutlined} from '@ant-design/icons-vue';
import {onMounted, reactive} from "vue";
import {getCaInfo, getSystemInfo} from "../../api/client/home.js";

const info = reactive({
  A: 0,
  B: 0,
  C: 0,
})

onMounted(() => {
  getSystemInfo().then(res => {
    if (res.code === 200) {
      info.A=(res.data.mem.used/1024/1024/1024).toFixed(2)
      info.B=(res.data.mem.free/1024/1024/1024).toFixed(2)
      info.C=(res.data.disk.used/1024/1024/1024).toFixed(2)
    }
  })
})

const downloadTextFile=(content, filename)=> {
  // 创建一个Blob对象，其中包含文件内容
  const blob = new Blob([content], { type: 'text/plain' });

  // 创建一个下载链接
  const link = document.createElement('a');

  // 使用URL.createObjectURL为Blob对象创建一个临时URL
  link.href = URL.createObjectURL(blob);

  // 设置下载文件的名称
  link.download = filename;

  // 触发点击事件来开始下载
  link.click();

  // 释放临时URL
  URL.revokeObjectURL(link.href);
}

const downCa=()=>{
  getCaInfo().then(res=>{
    console.log(res)
    downloadTextFile(res.data, "Lktx-RootCa.cer");
  })
}

</script>

<style scoped lang="less">

.one {
  padding: 5rem 2rem;
  background-color: #4b6ff6;
}

.two {
  padding: 5rem 2rem;
  background-color: #ffffff;
}


.data {
  max-width: 1024px;
  min-width: 300px;
}

.menu-head {
  width: 100%;
  z-index: 999;
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  font-size: 1.2rem;
  background-color: #4b6ff6;
  color: #fff;
}

.menu-data {
  padding: 1rem 2rem;
  margin: 0 auto;
  text-align: center;
  display: flex;
  justify-content: space-between;
}

.menu-btn {
  margin: 0 10px;
}

.foot {
  padding: 2rem;
  height: auto;
  position: absolute;
  left: 0;
  width: 100%;
  background-color: #4b6ff6;
  color: #ffffff;
}

.sm {
  h1 {
    color: #333;
    font-size: 24px;
    margin-bottom: 10px;
  }

  p {
    color: #555;
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 15px;
  }

  ol {
    margin-left: 30px;
    margin-bottom: 15px;
  }

  li {
    color: #555;
    font-size: 16px;
    line-height: 1.5;
  }
}

</style>
